package com.zndroid.logcat.core;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.zndroid.logcat.Config;
import com.zndroid.logcat.displayer.FloatingWindow;

/**
 * Created by lzy on 2021/1/14.
 */
public final class CatDelegate {
    private Config config;
    private FloatingWindow floatingWindow;

    public CatDelegate(Config config) {
        this.config = config;
    }

    public void setConfig(Config config) {
        this.config = config;
    }

    public void showLogcat(Context context) {
        if (null != floatingWindow && floatingWindow.isShow()) {
            return;
        }

        if (context instanceof Application) {
            floatingWindow = new FloatingWindow((Application) context);
        } else if (context instanceof Activity) {
            floatingWindow = new FloatingWindow((Activity) context);
        }

        if (null != floatingWindow) {
            floatingWindow.show();
        }
    }

    public void closeLogcat() {
        if (null != floatingWindow) {
            floatingWindow.cancel();
        }
    }
    
    public boolean isShow() {
        if (null == floatingWindow) {return false;}
        return floatingWindow.isShow();
    }
}
